#include "usart.h"
#include "my_delay.h"
#include "wifi.h"

void wifiInit()
{	
//	OLED_ShowString(10,20,"WIFI is connecting...",12,1);
//	OLED_Refresh();
	myDelayMs(500);

	usartSendStr(USART2,"AT+RESTORE\r\n",sizeof("AT+RESTORE\r\n"));
	myDelayMs(2000);
	
	//设置为STA + AP模式
	usartSendStr(USART2,"AT+CWMODE=3\r\n",sizeof("AT+CWMODE=3\r\n"));
	myDelayMs(300);

	//开启多连接
	usartSendStr(USART2,"AT+CIPMUX=1\r\n",sizeof("AT+CIPMUX=1\r\n"));
	myDelayMs(300);
	
	//连接WIFI：YinYuanPC，11223344
	usartSendStr(USART2,"AT+CWJAP_DEF=\"YinYuanPC\",\"11223344\"\r\n",sizeof("AT+CWJAP_DEF=\"YinYuanPC\",\"11223344\"\r\n"));
	myDelayMs(7000);

	//连接服务器：192.168.40.159,8888
	usartSendStr(USART2,"AT+CIPSTART=0,\"TCP\",\"192.168.40.159\",8888\r\n",sizeof("AT+CIPSTART=0,\"TCP\",\"192.168.40.159\",8888\r\n"));
	myDelayMs(300);

	//开启WIFI：Y_ESP8266，11223344
	usartSendStr(USART2,"AT+CWSAP=\"Y_ESP8266\",\"11223344\",5,3,4,0\r\n",sizeof("AT+CWSAP=\"Y_ESP8266\",\"11223344\",5,3,4,0\r\n"));
	myDelayMs(300);

	//开启服务器
	usartSendStr(USART2,"AT+CIPSERVER=1,8080\r\n",sizeof("AT+CIPSERVER=1,8080\r\n"));
	myDelayMs(300);

	//设置永不超时
	usartSendStr(USART2,"AT+CIPSTO=0\r\n",sizeof("AT+CIPSTO=0\r\n"));

}

